package com.aggron.concurrency.examples.singeton;

import com.aggron.concurrency.annotations.NotRecommend;
import com.aggron.concurrency.annotations.ThreadSafe;

/**
 * @author LR2SD
 * @description 懒汉模式--在第一次使用类的实例的时候创建，synchronized在多线程下不会会有线程安全问题，但开销过大
 * @date 2018-06-10 15:52
 */
@ThreadSafe
@NotRecommend
public class SingletonExample1 {

    private static SingletonExample1 singletonExample1=null;

    private SingletonExample1(){

    }

    /**
     * 静态工场模式
     * @return
     */
    public static synchronized  SingletonExample1 getInstance(){
        if(singletonExample1==null){
            singletonExample1=new SingletonExample1();
        }
        return singletonExample1;
    }
}
